﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Quartz.Impl;
using Quartz.Logging;

namespace Quartz.NET.Newer.WindowsFormsApp
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter { Level = LogLevel.Info };
            LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());
            var scheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
            scheduler.Start().Wait();

            Application.Run(new Form1());
            scheduler.Shutdown().Wait();
        }
    }

    //LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());

    internal class ConsoleLogProvider : ILogProvider
    {
        public Logger GetLogger(string name)
        {
            return (level, func, exception, parameters) =>
            {
                if (level >= LogLevel.Info && func != null)
                {
                    Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] [" + level + "] " + func(), parameters);
                }
                return true;
            };
        }

        public IDisposable OpenNestedContext(string message)
        {
            throw new NotImplementedException();
        }

        public IDisposable OpenMappedContext(string key, object value, bool destructure = false)
        {
            throw new NotImplementedException();
        }
    }

}
